import { MutationTree } from 'vuex'
import { UserState } from './state'

export enum UserMutationTypes {
  SET_TOKEN = 'SET_TOKEN',
  SET_NAME = 'SET_NAME',
  SET_ROLES = 'SET_ROLES'
}

export interface UserMutations<U = UserState> {
  [UserMutationTypes.SET_TOKEN]: (state: U, token: string) => void
  [UserMutationTypes.SET_NAME]: (state: U, name: string) => void
  [UserMutationTypes.SET_ROLES]: (state: U, roles: string[]) => void
}
const mutations: MutationTree<UserState> & UserMutations<UserState> = {
  [UserMutationTypes.SET_TOKEN](state, token) {
    state.token = token
  },

  [UserMutationTypes.SET_NAME](state, name) {
    state.name = name
  },
  [UserMutationTypes.SET_ROLES](state, roles) {
    state.roles = roles
  }
}

export default mutations
